/**************************************************************************************************
* Title: SmurfsRenderObject.cpp
* Authors: Gael Huber
* Description: Wrapper class for a render object
**************************************************************************************************/
#include "SmurfsMesh.h"

// Constructor
Mesh::Mesh(void) : data(0), screenCoords(Vector3(0,0,0)), angle(0.0f), dimensions(Vector3(0.5f,0.5f,0.5f)),
	halfDimensions(Vector3(0.25f,0.25f,0.25f)), rotationAxis(Vector3(1.0f,1.0f,1.0f)), resourceID(-1), objectID(-1) {
	// Do nothing
}

// Constructor
Mesh::Mesh(MeshType shape) : data(0), screenCoords(Vector3(0,0,0)), angle(0.0f), dimensions(Vector3(0.5f,0.5f,0.5f)),
	halfDimensions(Vector3(0.25f,0.25f,0.25f)), rotationAxis(Vector3(1.0f,1.0f,1.0f)), resourceID(-1), objectID(-1) {
	type = shape;

	// Set to draw a pyramid
	/*if(type == PYRAMID) {
		colors.push_back(Vector3(0.0f,1.0f,0.0f));			// Set The Color To Green
		vertices.push_back(Vector3( 0.0f, 0.25f, 0.0f));			// Top Of Triangle (Front)
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, 0.25f));		// Left Of Triangle (Front)
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f, 0.25f));		// Right Of Triangle (Front)

		colors.push_back(Vector3(1.0f,0.5f,0.0f));			// Set The Color To Orange
		vertices.push_back(Vector3( 0.0f, 0.25f, 0.0f));			// Top Of Triangle (Right)
		colors.push_back(Vector3(1.0f,0.5f,0.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f, 0.25f));		// Left Of Triangle (Right)
		colors.push_back(Vector3(1.0f,0.5f,0.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f, -0.25f));		// Right Of Triangle (Right)

		colors.push_back(Vector3(0.0f,0.0f,1.0f));			// Set The Color To Blue
		vertices.push_back(Vector3( 0.0f, 0.25f, 0.0f));			// Top Of Triangle (Back)
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f, -0.25f));		// Left Of Triangle (Back)
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, -0.25f));		// Right Of Triangle (Back)

		colors.push_back(Vector3(1.0f,0.0f,1.0f));			// Set The Color To Violet
		vertices.push_back(Vector3( 0.0f, 0.25f, 0.0f));			// Top Of Triangle (Left)
		colors.push_back(Vector3(1.0f,0.0f,1.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f,-0.25f));		// Left Of Triangle (Left)
		colors.push_back(Vector3(1.0f,0.0f,1.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, 0.25f));		// Right Of Triangle (Left)

		colors.push_back(Vector3(1.0f,1.0f,0.0f));			// Set The Color To Yeller
		vertices.push_back(Vector3(-0.25, -0.25f, -0.25));			// Top Of Triangle (Bottom)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3(0.25f,-0.25f,-0.25f));		// Left Of Triangle (Bottom)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3(0.25f,-0.25f, 0.25f));		// Right Of Triangle (Bottom)

		colors.push_back(Vector3(1.0f,1.0f,0.0f));			// Set The Color To Yeller
		vertices.push_back(Vector3(0.25f, -0.25f, 0.25f));			// Top Of Triangle (Bottom)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f,0.25f));		// Left Of Triangle (Bottom)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, -0.25f));		// Right Of Triangle (Bottom)
	} 
	// Set to draw a cube
	else if(type == CUBE) {
		colors.push_back(Vector3(0.0f,1.0f,0.0f));			// Set The Color To Green
		vertices.push_back(Vector3( 0.25f, 0.25f,-0.25f));			// Top Right Of The Quad (Top)
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f, 0.25f,-0.25f));			// Top Left Of The Quad (Top)
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f, 0.25f, 0.25f));			// Bottom Left Of The Quad (Top)
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(Vector3( 0.25f, 0.25f, 0.25f));			// Bottom Right Of The Quad (Top)

		colors.push_back(Vector3(1.0f,0.5f,0.0f));			// Set The Color To Orange
		vertices.push_back(Vector3( 0.25f,-0.25f, 0.25f));			// Top Right Of The Quad (Bottom)
		colors.push_back(Vector3(1.0f,0.5f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, 0.25f));			// Top Left Of The Quad (Bottom)
		colors.push_back(Vector3(1.0f,0.5f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f,-0.25f));			// Bottom Left Of The Quad (Bottom)
		colors.push_back(Vector3(1.0f,0.5f,0.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f,-0.25f));			// Bottom Right Of The Quad (Bottom)

		colors.push_back(Vector3(1.0f,0.0f,0.0f));			// Set The Color To Red
		vertices.push_back(Vector3( 0.25f, 0.25f, 0.25f));			// Top Right Of The Quad (Front)
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(Vector3(-0.25f, 0.25f, 0.25f));			// Top Left Of The Quad (Front)
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, 0.25f));			// Bottom Left Of The Quad (Front)
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f, 0.25f));			// Bottom Right Of The Quad (Front)

		colors.push_back(Vector3(1.0f,1.0f,0.0f));			// Set The Color To Yellow
		vertices.push_back(Vector3( 0.25f,-0.25f,-0.25f));			// Bottom Left Of The Quad (Back)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f,-0.25f));			// Bottom Right Of The Quad (Back)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3(-0.25f, 0.25f,-0.25f));			// Top Right Of The Quad (Back)
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(Vector3( 0.25f, 0.25f,-0.25f));			// Top Left Of The Quad (Back)

		colors.push_back(Vector3(0.0f,0.0f,1.0f));			// Set The Color To Blue
		vertices.push_back(Vector3(-0.25f, 0.25f, 0.25f));			// Top Right Of The Quad (Left)
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(Vector3(-0.25f, 0.25f,-0.25f));			// Top Left Of The Quad (Left)
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f,-0.25f));			// Bottom Left Of The Quad (Left)
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(Vector3(-0.25f,-0.25f, 0.25f));			// Bottom Right Of The Quad (Left)

		colors.push_back(Vector3(1.0f,0.0f,1.0f));			// Set The Color To Violet
		vertices.push_back(Vector3( 0.25f, 0.25f,-0.25f));			// Top Right Of The Quad (Right)
		colors.push_back(Vector3(1.0f,0.0f,1.0f));
		vertices.push_back(Vector3( 0.25f, 0.25f, 0.25f));			// Top Left Of The Quad (Right)
		colors.push_back(Vector3(1.0f,0.0f,1.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f, 0.25f));			// Bottom Left Of The Quad (Right)
		colors.push_back(Vector3(1.0f,0.0f,1.0f));
		vertices.push_back(Vector3( 0.25f,-0.25f,-0.25f));			// Bottom Right Of The Quad (Right)
	}*/

	// Set to draw a sphere
	if(type == SPHERE) {
		// Storage of 12 points from which we make our shape
		Vector3* points = new Vector3[12];
		
		// Define a rectangle in x-y space
		Vector3 tl = Vector3(-0.5f, 0.25f, 0) / 2.0f;
		Vector3 tr = Vector3(0.5f, 0.25f, 0) / 2.0f;
		Vector3 br = Vector3(0.5f, -0.25f, 0) / 2.0f;
		Vector3 bl = Vector3(-0.5, -0.25f, 0) / 2.0f;

		// Store the points in the temporary array
		points[0] = tl; points[1] = tr; points[2] = br; points[3] = bl;

		// Define the quaternion for our first rotation
		Quaternion q = Quaternion(PI / 2, Vector3(0.0f, 1.0f, 0.0f)) * Quaternion(-PI / 2, Vector3(1.0f, 0.0f, 0.0f));

		// Rotate the points
		tl.rotate(q);
		tr.rotate(q);
		br.rotate(q);
		bl.rotate(q);

		// Store the points in the temporary array
		points[4] = tl; points[5] = tr; points[6] = br; points[7] = bl;

		// Define the quaternion for our first rotation
		q = Quaternion(PI / 2, Vector3(0.0f, 1.0f, 0.0f)) * Quaternion(-PI / 2, Vector3(1.0f, 0.0f, 0.0f));

		// Rotate the points
		tl.rotate(q);
		tr.rotate(q);
		br.rotate(q);
		bl.rotate(q);

		/*colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(tl);
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(tr);
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(br);
		colors.push_back(Vector3(1.0f,1.0f,0.0f));
		vertices.push_back(bl);*/


		// Store the points in the temporary array
		points[8] = tl; points[9] = tr; points[10] = br; points[11] = bl;

		// Create the different triangles in the shape
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[8]);
		vertices.push_back(points[4]);
		vertices.push_back(points[7]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[8]);
		vertices.push_back(points[4]);
		vertices.push_back(points[0]);

		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(points[0]);
		vertices.push_back(points[4]);
		vertices.push_back(points[3]);

		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[0]);
		vertices.push_back(points[3]);
		vertices.push_back(points[5]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[4]);
		vertices.push_back(points[3]);
		vertices.push_back(points[11]);

		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(points[4]);
		vertices.push_back(points[7]);
		vertices.push_back(points[11]);

		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[2]);
		vertices.push_back(points[7]);
		vertices.push_back(points[11]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[3]);
		vertices.push_back(points[11]);
		vertices.push_back(points[10]);

		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(points[2]);
		vertices.push_back(points[10]);
		vertices.push_back(points[11]);

		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[2]);
		vertices.push_back(points[1]);
		vertices.push_back(points[7]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[7]);
		vertices.push_back(points[8]);
		vertices.push_back(points[1]);

		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(points[0]);
		vertices.push_back(points[9]);
		vertices.push_back(points[8]);

		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[8]);
		vertices.push_back(points[9]);
		vertices.push_back(points[1]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[0]);
		vertices.push_back(points[9]);
		vertices.push_back(points[5]);

		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(points[5]);
		vertices.push_back(points[9]);
		vertices.push_back(points[6]);

		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[6]);
		vertices.push_back(points[9]);
		vertices.push_back(points[1]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[1]);
		vertices.push_back(points[2]);
		vertices.push_back(points[6]);

		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		colors.push_back(Vector3(0.0f,0.0f,1.0f));
		vertices.push_back(points[6]);
		vertices.push_back(points[10]);
		vertices.push_back(points[2]);

		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		colors.push_back(Vector3(1.0f,0.0f,0.0f));
		vertices.push_back(points[10]);
		vertices.push_back(points[3]);
		vertices.push_back(points[5]);

		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		colors.push_back(Vector3(0.0f,1.0f,0.0f));
		vertices.push_back(points[10]);
		vertices.push_back(points[6]);
		vertices.push_back(points[5]);

	}
	
}

// Destructor
Mesh::~Mesh(void) {
	// Do nothing
}